package com.ithema;

import com.ithema.domain.Student;

import java.util.ArrayList;
import java.util.Scanner;

public class Test3 {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<Student>();
        //创建集合对象

        //创建学生对象
        Student stu1 = getStudents();
        Student stu2 = getStudents();
        Student stu3 = getStudents();

        //添加学生对象到集合
        list.add(stu1);
        list.add(stu2);
        list.add(stu3);

        //遍历数组,采用通用格式实现
        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);
            stu.show();
        }
    }
    //当方法的返回值是一个类名时,方法中药返回的是该类的对象
    //当方法的参数类型是一个类名时,调用方法时要传递的对象是该类的对象
    public static Student getStudent(){
        Student stu = getStudents();
        return  stu;
    }

    private static Student getStudents() {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入姓名:");

        String name = sc.next();
        System.out.println("请输入学生年龄:");
        int age = sc.nextInt();
        return new Student(name,age);
    }
}
